package com.sdry.web.controller.llm;

import com.github.pagehelper.PageHelper;
import com.sdry.model.cb.ReportFormEntity;
import com.sdry.model.jyy.Receive;
import com.sdry.model.lz.OutStockOrder;
import com.sdry.service.cb.ReportFormService;
import com.sdry.utils.ResponseUtil;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 看板
 * @author llm
 * @date 2019年10月8日
 * @version 1.0
 */
@Controller
@RequestMapping("/spectaculars")
public class Spectaculars {

	 @Autowired
	 private ReportFormService reportFormService;
	 
	/** 
	 * 进入页面
	 * @return 页面路径
	*/
	@RequestMapping("/page")
	public ModelAndView pageDeliveryNode () {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/spectaculars/spectaculars");
		return mv;
	}
	
	/*-------------APP -------------------------------------------*/
	/**
	 * 入库看板（测试数据）
	 * @param response
	 */
	@RequestMapping("/inventory")
	public void inventory(HttpServletResponse response){
        PageHelper.startPage(1,10);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String time = sdf.format(new Date());
        String time2 = sdf2.format(new Date());
        List<Receive> list = reportFormService.getReportFormJinList("", "", time, null, "2", time2, 1, 10);
       /* List<Receive> list = new ArrayList<Receive>();
        for(int i = 0; i < 6; i ++){
        	Receive r = new Receive();
            r.setCreateDate(time);
            r.setIsSimple("0");
            r.setReceiveNumber("R-1570578459352");
            r.setReceive_company("0");
            r.setRemark("");
            r.setSendCompany("SA2FC-8123430仪表板左除霜风道总成");
            r.setSendDate("440");
            r.setSendName("68009010");
            r.setSendPhone("奇跃");
            list.add(r);
        }*/
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("status", "1");
		jsonObject.put("data", list);
		try {
			ResponseUtil.write(response, jsonObject);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 出库看板（测试数据）
	 * @param response
	 */
	@RequestMapping("/removeal")
	public void removeal(HttpServletResponse response){
        PageHelper.startPage(1,10);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		String time = sdf.format(new Date());
		String time2 = sdf2.format(new Date());
        //List<Receive> list = reportFormService.getReportFormJinList(null, null, time, null, null, time);
		List<OutStockOrder> list = reportFormService.getReportFormChungList("", "", null, time, "3", time2, 1, 10);
       /* List<OutStockOrder> list = new ArrayList<OutStockOrder>();
        for(int i = 0; i < 6; i ++){
        	OutStockOrder o = new OutStockOrder();
            o.setContacts_tel("奇跃");
            o.setCreate_date(time);
            o.setCustomer_id(28L);
            o.setOut_stock_num("CKDH-1570554449423");
            o.setRemark("");
            o.setSource(0);
            o.setStatus(0);
            o.setTab(0);
            o.setType(0);
            o.setUserName("88");
            o.setWarehouse_address("68013629");
            o.setWarehouse_name("CNSL_ARMREST_OUTER_COVER副仪表板扶手外板骨架");
            list.add(o);
        }*/
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("status", "1");
		jsonObject.put("data", list);
		try {
			ResponseUtil.write(response, jsonObject);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

    /**
     *
     * @param response
     */
    @RequestMapping("/appReport")
    public void appReport(HttpServletResponse response) {
        PageHelper.startPage(1,10);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String time = sdf.format(new Date());
        List<ReportFormEntity> list = null;
        try {
            list = reportFormService.getDateBalance("", time, null, "", "2020-01-01", 1, 10);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", "1");
        jsonObject.put("data", list);
        try {
            ResponseUtil.write(response, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
